//
// Created by LiuDongPeng on 2023/11/29.
//

#ifndef FOC_AS5047P_H
#define FOC_AS5047P_H


#include <stdint.h>
#include <stddef.h>



/**
 * @brief register group
 */
#define AS5047P_ADDR_NOP        0x0000
#define AS5047P_ADDR_ERRFL      0x0001
#define AS5047P_ADDR_PROG       0x0003
#define AS5047P_ADDR_ANGLEUNC   0x3FFE
#define AS5047P_ADDR_ANGLECOM   0x3FFF




typedef struct as5047p
{
    int (*spi_send_recv_callback)(uint8_t* pTxData, uint8_t* pRxData, uint16_t size, uint32_t timeOut);
    void (*spi_cs_set_callback)(uint8_t val);
    uint8_t cs_valid_level; // low level

    float resolution; // 14bit 0x3fff

} as5047p_t;


typedef int (*spi_send_recv_callback_t)(uint8_t* pTxData, uint8_t* pRxData, uint16_t size, uint32_t timeOut);
typedef void (*spi_cs_set_callback_t)(uint8_t val);


int as5047p_init(as5047p_t* dev, spi_send_recv_callback_t spi_send_recv_handle, spi_cs_set_callback_t spi_cs_set_handle);

int as5047p_get_raw_data(as5047p_t* dev, float* raw);
int as5047p_get_data(as5047p_t* dev, float* raw, float* angle, float* rad);


#endif //FOC_AS5047P_H
